#ifndef _MERGETRIANGLEOPERATOR_H_
#define _MERGETRIANGLEOPERATOR_H_

#include "Osg2CesiumDef.h"
#include "osg.h"
#include <osg/TriangleLinePointIndexFunctor>

namespace OCPP
{
    inline osg::BoundingBox getBoundBox(osg::Node* node)
    {
        osg::ComputeBoundsVisitor cbv;
        node->accept(cbv);
        return cbv.getBoundingBox();
    }

    class GltfTriangleOperator
    {
    public:
        osg::ref_ptr<osg::Vec3Array>        pos;
        osg::ref_ptr<osg::Vec3Array>        nor;
        osg::ref_ptr<osg::DrawElementsUInt> set;

        //outline
        osg::ref_ptr<osg::DrawElementsUInt> lineSet;
        osg::ref_ptr<osg::Vec3Array>        mPosition;
        std::map<std::string, std::string>  mEdges;
        unsigned int offset = 0;
        std::map<osg::Vec2i, int> mapRepeat2;
        std::map<osg::Vec3i, int> mapRepeat3;
        void addTri(unsigned int p1, unsigned int p2, unsigned int p3);
        void genEdgeSet();

        inline void operator()(unsigned int p1)
        {

        }

        inline void operator()(unsigned int p1, unsigned int p2)
        {
            osg::Vec2i tri(p1 + offset, p2 + offset);
            if (mapRepeat2.find(tri) != mapRepeat2.end())
            {
                return;
            }

            mapRepeat2[tri] = 1;

            set->addElement(tri.x());
            set->addElement(tri.y());
        }
        inline void operator()(unsigned int p1, unsigned int p2, unsigned int p3)
        {
            addTri(p1, p2, p3);
        }
    };

    typedef osg::TriangleLinePointIndexFunctor<GltfTriangleOperator> GltfTriangleIndexFunctor;
}

#endif // !1
